import tkinter as tk

from com.cqt.gui.tk.layout import Pack, Grid, Place


class window:
    def __init__(self, layout=None, components=[], window_settings={}):
        self.root = tk.Tk()
        self.window_settings_map = {
            'title': self.root.title,
            'size':self.size
        }
        self.parse_window_settings(window_settings)
        # self.root.title("默认")
        tl = tk.Button(text='我是一个标签')
        # 第一个参数是想要设置的列的序号
        self.root.grid_columnconfigure(1, weight=1)

        # 用于设置行
        self.root.grid_rowconfigure(1, weight=1)
        #Pack().v(fill=tk.BOTH,marginX=200,anchor=tk.W).bind(tl)
        # Grid().v(row=0, column=0, rowspan=1).bind(tk.Button(self.root, text="1",width=5,height=5))
        # Grid().v(row=0, column=1, rowspan=1).bind(tk.Button(self.root, text="2",width=5,height=5))
        # Grid().v(row=0,column=2,rowspan=1).bind(tk.Button(self.root,text="3",width=5,height=5))
        #
        # Grid().v(row=4,column=2,rowspan=2).bind(tk.Button(self.root,text="4",width=5,height=5))

        (Place().v(x=100,y=20,width=30,height=50,bordermode=tk.OUTSIDE)
         .bind(tk.Button(self.root,text="1",activebackground='red',activeforeground='blue',bd=3,bg='yellow')))

        Place().v(x=100, y=80, width=30, height=50).bind(tk.Button(self.root, text="2"))

    def mainloop(self):
        #self.root.geometry("200x300")
        self.root.mainloop()

    def size(self,size):
        w =size[0]
        h=size[1]
        x=size[2]
        y=size[3]
        self.root.geometry("%dx%d+%d+%d"%(w,h,x,y))

    def parse_window_settings(self, window_settings):
        for k in window_settings.keys():
            v = window_settings[k]
            vf = self.window_settings_map[k]
            vf(v)


if __name__ == "__main__":
    window(window_settings={
        'title': '窗口1',
        'size': [500, 200, 0, 0]
    }).mainloop()
